import requests
import json


def translate_word(word):
    url = 'https://fanyi.baidu.com/sug'


    headers = {
        'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
    }

  
    data = {
        'kw': word
    }

    try:

        response = requests.post(url, headers=headers, data=data)
        result = response.json()


        if result.get('data'):
            translations = [item['v'] for item in result['data']]
            print(f"'{word}' 的翻译结果:")
            for trans in translations:
                print(trans)
        else:
            print("未找到翻译结果")

    except Exception as e:
        print(f"翻译出错: {e}")


if __name__ == '__main__':
    word = input("请输入需要翻译的单词: ")
    translate_word(word)